
import {observable,action} from 'mobx'
import {List} from "../../../../api/work/config/cloud/CloudApi";

class Store {
    // 搜索条件
    @observable searchMap = {};

    //列表
    @observable records = [];

    //详情
    @observable record = {};

    //表格加载
    @observable isFetching = false;

    //表单显示控制
    @observable formVisible = false;

    //弹窗加载控制
    @observable confirmLoading = false;

    //总数
    @observable total=0;

    //页码
    @observable page=1;

    //每页大小
    @observable pageSize=10;

    @action fetchRecords(){
        this.isFetching  = true;
        this.searchMap["page"] = this.page;
        this.searchMap["pageSize"] = this.pageSize;
        List(this.searchMap).then(response => {
            if (response.data.code === 200){
                this.records = response.data.list;
                this.total = parseInt(response.data.pager.totalCount);
            }
        }).finally(() => this.isFetching = false)
    }

    @action showForm(record={}){
        this.record = record;
        this.formVisible = true;
    }

    @action handleReset = () => {
        this.searchMap = {};
        this.fetchRecords();
    };

    @action handleSearch = () => {
        this.fetchRecords();
    };
}

export default new Store();
